package com.xx.springboot.DataStructure.Stack;


import com.xx.springboot.DataStructure.LinkedList.LinkedList;


/**
 * @description: 实现一个基于链表的栈
 * @author: xiaoxiunique
 * @date: 2018年7月26日 09:11:42
 * @param <T>
 */
public class LinkedListStack<T> implements Stack<T> {


    private LinkedList<T> linkedList;


    /**
     * 初始话构造函数
     */
    public LinkedListStack() {
        linkedList = new LinkedList<T>();
    }

    /**
     * 获取得到链表的长度
     * @return
     */
    public int size() {
        return linkedList.getSize();
    }

    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    public void push(T t) {
        linkedList.addLast(t);
    }

    public T pop() {
        return linkedList.removeLast();
    }

    public T peek() {
        return linkedList.getLast();
    }

    @Override
    public String toString() {

        StringBuffer res = new StringBuffer();
        res.append("LinkedListStack: top ");
        res.append(linkedList);
        return res.toString();
    }


}
